package com.benson.generic.bound;

import java.util.ArrayList;
import java.util.List;

public class GenericWriting {

	static <T> void writeExact(T item,List<T> list){
		list.add(item);
	}
	
	static List<Apple> apples = new ArrayList<Apple>();
	static List<Fruit> fruit = new ArrayList<Fruit>();
	
	static void f1(){
		writeExact( new Apple(),apples);
		
		writeExact( new Fruit(),fruit);
		
		writeExact( new Apple(),fruit);
		
//		writeExact( new Fruit(),apples);
	}
	
	static <T> void writeWithWildcard(List<? super T> list, T item){
		list.add(item);
	}
	
	static void f2(){
		writeWithWildcard(apples, new Apple());
		
		writeWithWildcard(fruit, new Fruit());
		
		writeWithWildcard(fruit, new Apple());
	}
	
	public static void main(String[] args) {
		f1();
		f2();
	}
}
